package handler

import (
	"cam-master/model"
	"github.com/gin-gonic/gin"
)

func CreateComputer(c *gin.Context) {
	title := c.PostForm("title")
	content := c.PostForm("content")
	Img := c.PostForm("img")
	data := model.Computer{

		Title:   title,
		Content: content,
		Img:     Img,
	}
	err := model.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 500,
		"msg":  "添加成功",
		"data": data,
	})
	return
}

func ListComputer(c *gin.Context) {
	var computer []model.Computer
	err := model.DB.Find(&computer).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "获取数据失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "获取成功",
		"data": computer,
	})
	return

}
